﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SoftHelper.Tool
{
    public class RalyCommand : ICommand
    {
        private readonly Action<Object> m_execute;
        private readonly Predicate<Object> m_canExecute;

        public RalyCommand(Action<Object> execute)
        {
            this.m_execute = execute;
        }

        public RalyCommand(Action<Object> m_execute,Predicate<Object> m_canexecute)
        {
            this.m_execute = m_execute;
            this.m_canExecute = m_canexecute;
        } 

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public bool CanExecute(object parameter)
        {
            if (m_canExecute!=null)
            {
                return true;
            }
            return m_canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            this.m_execute(parameter);
        }
    }
}
